﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using Org.Eurekaa.DNJ.Settings;

namespace Org.Eurekaa.DNJ.UI.DNJSettings
{
    [TypeConverter(typeof(ExpandableObjectConverter))]
    [Serializable()]
    public class DNJAccordionEvents : GenericSettingsObject
    {

        [Description("This event is triggered every time the accordion changes. If the accordion is animated, the event will be triggered upon completion of the animation; otherwise, it is triggered immediately.")]
        [DefaultValue(""), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        [PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public UIEventFunction Change
        {
            get { return Get<UIEventFunction>("change"); }
            set { this["change"] = value; }
        }

        [Description("This event is triggered every time the accordion starts to change. ")]
        [DefaultValue(""), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        [PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public UIEventFunction Changestart
        {
            get { return Get<UIEventFunction>("changestart"); }
            set { this["changestart"] = value; }
        }

        public DNJAccordionEvents()
        {
            this["change"] = new UIEventFunction();
            this["changestart"] = new UIEventFunction();
        }

        public string GetDefaultEventsScript()
        {
            String evtScript = String.Empty;
            foreach (UIEventFunction evt in Settings.Values)
            {
                if (!string.IsNullOrEmpty(evt.Name))
                {
                    evtScript += "if (!window." + evt.Name.Trim() + "){" + evt.Name.Trim() + " = new Function(\"return dnjDefaultEvent('" + evt.Name.Trim() + "')\");}";
                }
            }

            return evtScript;
        }
        public override string ToString()
        {
            return base.ToString();
        }

    }

}
